package Test.YQNTest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public enum City {
    //考虑到js代码里边有城市的x y坐标，感觉也可以一起维护到枚举里边，后面只需要查一遍即可。
    BEIJING(0, "北京", 300, 300),
    SHANGHAI(1, "上海", 800, 300),
    GUANGZHOU(2, "广州", 550, 100),
    SHENZHEN(3, "深圳", 550, 500),
    CHENGDU(4, "成都", 200, 100),
    HANGZHOU(5, "杭州", 200, 500);

    private final int code;
    private final String name;
    private final int x;
    private final int y;

    City(int code, String name, int x, int y) {
        this.code = code;
        this.name = name;
        this.x = x;
        this.y = y;
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    /**
     * @return 返回城市总数
     */
    public static int getCitiNum() {
        return City.values().length;
    }

    /**
     * @param name 中文城市名
     * @return  返回枚举
     */
    public static City getCityByName(String name) {
        for (City city : City.values()) {
            if (city.getName().equals(name)) {
                return city;
            }
        }
        return null; // 如果没有找到匹配的枚举常量，则返回null
    }

    /**
     * @return 返回包含所有City枚举值的List
     */
    public static List<City> getAllCities() {
        return new ArrayList<>(Arrays.asList(City.values()));
    }
}
